package com.jeanboy.app.luckygo;

import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import java.util.Random;

public class MainActivity extends AppCompatActivity {


    private LuckyMonkeyPanelView lucky_panel;
    private Button btn_action;
    private TextView textView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        lucky_panel = (LuckyMonkeyPanelView) findViewById(R.id.lucky_panel);
        btn_action = (Button) findViewById(R.id.btn_action);
        textView = (TextView)findViewById(R.id.tv_start);

        btn_action.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                textView.setText("");
                if (!lucky_panel.isGameRunning()) {
                    lucky_panel.startGame();
                } else {
                    final int stayIndex = new Random().nextInt(9);

                    Log.e("LuckyMonkeyPanelView", "====中奖号===" + stayIndex);
                    lucky_panel.tryToStop(stayIndex);
                    new Handler().postDelayed(new Runnable(){
                        public void run() {
                            textView.setText("恭喜"+ (stayIndex+1) +"号，获得表演机会一次");
                        }
                    }, 2000);



                }
            }
        });
    }
}
